<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2021/1/7
 * Time: 14:41
 */

namespace app\admin\controller;


use think\Db;

class Usersign extends Base
{
    /**
     * 首页
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax()){
            $start_time = input('start_time');
            $end_time = input('end_time');
            $user_phone = input('user_phone');
            
            $where = [];
            if(isset($user_phone) && $user_phone != ''){
                $where['user_phone'] = ['like', '%' . $user_phone . '%'];
            }
            if(isset($start_time) && $start_time != '' && isset($end_time) && $end_time == '')
            {
                $where['sign_datetime'] = ['>= time', $start_time];
            }
            if(isset($start_time) && $start_time == '' && isset($end_time) && $end_time != '')
            {
                $where['sign_datetime'] = ['<= time', $end_time];
            }
            if(isset($start_time) && $start_time != '' && isset($end_time) && $end_time != '')
            {
                $where['sign_datetime'] = ['between time', [$start_time, $end_time]];
            }
                
            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('user_sign')
                ->join('up_u_user', 'user_id = sign_user_id', 'LEFT')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('user_sign')
                ->join('up_u_user', 'user_id = sign_user_id', 'LEFT')
                ->field('sign_id, sign_user_id, user_username, user_phone, sign_district, sign_datetime')
                ->where($where)
                ->order('sign_datetime desc')
                ->page($NowPage, $limits)
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
}